<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>AJAX.OOP - OOP Engine Browser Test</title>
<script type="text/javascript" src="../ajaxoop.js"></script>
<style type="text/css">
.passed {
	background:#9f9;
	padding:3px;
	margin:3px;
	border:1px dotted #888;
}
.failed {
	background:#f99;
	padding:3px;
	margin:3px;
	border:1px dotted #888;

</style>
</head>
<body>
<h1>AJAX.OOP - OOP Engine Browser Test</h1>
<p>&nbsp;&nbsp;&nbsp;<a href="/">&lt;&lt; Return To Home Page</a></p>
<p>Current Browser: <strong>
<script type="text/javascript">
$d.writeln( $n.userAgent);
</script>
</strong></p>
<p>This test is maintain AJAX.OOP library to be successfull on a most of popular browsers. 
So you can run it under your browser application and check if OOP engine works fine. 
If at least one of a tests failed this mean that AJAX.OOP library is not compatible with your browser. 
In this case, please, <a target="_blank" href="http://code.google.com/p/ajaxoop/issues/entry">send us</a> your test results, 
your browser name and version to allow us to fix this problem.</p>
<p>At option you can <a href="javascript:sendReport();location.self;">send us</a> automatic bug report. Some private data about your IP and browser will be written
to our database. We guarantee that these data won't be used for any purposes except to analyse for application 
problem solving.</p>
<p>If you wish you can try to fix the problem yourselves and contribute your patches by becoming 
AJAX.OOP team member. Just go to <a target="_blank" href="http://ajaxoop.googlecode.com">http://ajaxoop.googlecode.com</a> 
and subscribe to become a team member.</p>
<h2>Results Of Testing:</h2>

<script type="text/javascript">
var TEST_CLASS_CREATE     = false;
var TEST_INHERIT          = false;
var TEST_INHERIT_NATIVE   = false;
var TEST_INHERIT_CHAIN    = false;
var TEST_OVERLOAD         = false;
var TEST_AGGREGATE        = false;
var TEST_AGGREGATE_PARENT = false;
var TEST_AGGREGATE_SELF   = false;
var TEST_INSTANCE         = false;

var errors = {};
var clean = true;

// 1. Test class creation
try {
	var myClass01 = Ajax.Class({});
	var my = new myClass01;
	if (Ajax.isObject( my)) {
		TEST_CLASS_CREATE = true;
	}
} catch (e) {
	errors['create'] = e;
	clean = false;
}

// 2. Test inheritance
try {
	var myBase02 = Ajax.Class({
		x : 1
	});
	var myClass02 = Ajax.Class(myBase02, {
		constructor : function() {
			if (this.x && this.x == 1 && this instanceof myBase02 && this instanceof myClass02) {
				this.x = 2;
				if (this.x == 2 && this.$super && this.$super.x == 1) {
					TEST_INHERIT = true;
				}
			}
		}
	});
	var my = new myClass02;
} catch (e) {
	errors['inherit'] = e;
	clean = false;
}

// 3. Test inheritance of native code

try {
	function myBase03() {
		this.x = 1;
	};
	var myClass03 = Ajax.Class(myBase03, {
		constructor : function() {
			this.$super.constructor();
			if (this.x && this.x == 1 && this instanceof myBase03 && this instanceof myClass03) {
				this.x = 2;
				if (this.x == 2 && this.$super && this.$super.x == 1) {
					TEST_INHERIT_NATIVE = true;
				}
			}
		}
	});
	var my = new myClass03;
} catch (e) {
	errors['inheritNative'] = e;
	clean = false;
}

// 4. Test inheritance chain

try {
	function myBase04() {
		this.x = 1;
	};
	var myClass04 = Ajax.Class( myBase04, {
		y : 0,
		w : 5,
		constructor : function() {
			this.y = 2;
			this.$super.constructor();
		},
		testInstance : function() {
			if ((this.z && this.z == 3 && this instanceof myChild04) || !(this.w && this.w == 5)) {
				TEST_INHERIT_CHAIN = false;
			}
		}
	});
	var myChild04 = Ajax.Class( myClass04, {
		z : 3,
		w : 4,
		constructor : function() {
			this.$super.constructor();
			if (
				this.x && this.x == 1
				&&
				this.y && this.y == 2
				&&
				this.z && this.z == 3
				&&
				this.w && this.w == 4
				&&
				this instanceof myBase04
				&&
				this instanceof myClass04
				&&
				this instanceof myChild04
			) {
				TEST_INHERIT_CHAIN = true;
				this.$super.testInstance();
			}
		}
	});
	var my = new myChild04;
} catch (e) {
	errors['inheritChain'] = e;
	clean = false;
}

// 5. Test overloading

try {
	var myBase05 = Ajax.Class({
		alarm : function( val) {
			TEST_OVERLOAD = true;
		}
	});
	var myClass05 = Ajax.Class( myBase05, {
		alarm : function() {
			this.$super.alarm( this.alarm != this.$super.alarm);
		}
	});
	
	var my = new myClass05;
	my.alarm( '123');
} catch (e) {
	errors['overload'] = e;
	clean = false;
}

// 6. Test aggregation

try {
	var myClass061 = Ajax.Class( {
		agg : null,
		constructor : function() {
			this.agg = new myClass062;
		}
	});
	var myClass062 = Ajax.Class( {});
	var my = new myClass061;
	if (my instanceof myClass061 && my.agg instanceof myClass062) {
		TEST_AGGREGATE = true;
	}
} catch (e) {
	errors['aggregate'] = e;
	clean = false;
}

// 7. Test parent aggregation

try {
	var myBase07 = Ajax.Class( {});
	var myClass07 = Ajax.Class( myBase07, {
		pobj : null,
		constructor : function() {
			this.pobj = new this.$_super();
		}
	});
	var my = new myClass07;
	if (my.pobj instanceof myBase07) {
		TEST_AGGREGATE_PARENT = true;
	}
} catch (e) {
	errors['aggregateParent'] = e;
	clean = false;
}

// 8. Test self aggregation

try {
	var myClass08 = Ajax.Class({
		sobj : null,
		init : function() {
			this.sobj = new this.$_self();
		}
	});
	var my = new myClass08;
	my.init();
	if (my.sobj instanceof myClass08) {
		TEST_AGGREGATE_SELF = true;
	}
} catch (e) {
	errors['aggregateSelf'] = e;
	clean = false;
}

// 9. Test instances

try {
	function myBase09() {};
	var mySubclass091 = Ajax.Class( myBase09, {});
	var mySubclass092 = Ajax.Class( mySubclass091, {});
	var mySubclass093 = Ajax.Class( mySubclass092, {});
	var mySubclass094 = Ajax.Class( mySubclass093, {});
	var mySubclass095 = Ajax.Class( mySubclass094, {});
	var myClass09 = Ajax.Class( mySubclass095, {});
	var my = new myClass09;
	if (
		my instanceof myClass09
		&&
		my instanceof mySubclass095
		&&
		my instanceof mySubclass094
		&&
		my instanceof mySubclass093
		&&
		my instanceof mySubclass092
		&&
		my instanceof mySubclass091
		&&
		my instanceof myBase09
	) {
		TEST_INSTANCE = true;
	}
} catch (e) {
	errors['instance'] = e;
	clean = false;
}

if (!clean) {
	for (var i in errors) {
		if (Ajax.isFunction( errors[i])) alert( i + ' = ' + errors[i]);
	}
}

$d.writeln( '<pre>');

$d.write( (TEST_CLASS_CREATE     ? '<div class="passed">' : '<div class="failed">') + 
			'Test class creation:             ' + (TEST_CLASS_CREATE     ? 'passed</div>' : 'failed</div>'));

$d.write( (TEST_INHERIT          ? '<div class="passed">' : '<div class="failed">') + 
			'Test inheritance:                ' + (TEST_INHERIT          ? 'passed</div>' : 'failed</div>'));

$d.write( (TEST_INHERIT_NATIVE   ? '<div class="passed">' : '<div class="failed">') +
			'Test inheritance of native code: ' + (TEST_INHERIT_NATIVE   ? 'passed</div>' : 'failed</div>'));

$d.write( (TEST_INHERIT_CHAIN    ? '<div class="passed">' : '<div class="failed">') +
			'Test inheritance chain:          ' + (TEST_INHERIT_CHAIN    ? 'passed</div>' : 'failed</div>'));

$d.write( (TEST_OVERLOAD         ? '<div class="passed">' : '<div class="failed">') +
			'Test overloading:                ' + (TEST_OVERLOAD         ? 'passed</div>' : 'failed</div>'));

$d.write( (TEST_AGGREGATE        ? '<div class="passed">' : '<div class="failed">') +
			'Test aggregation:                ' + (TEST_AGGREGATE        ? 'passed</div>' : 'failed</div>'));

$d.write( (TEST_AGGREGATE_PARENT ? '<div class="passed">' : '<div class="failed">') +
			'Test parent aggregation:         ' + (TEST_AGGREGATE_PARENT ? 'passed</div>' : 'failed</div>'));

$d.write( (TEST_AGGREGATE_SELF   ? '<div class="passed">' : '<div class="failed">') +
			'Test self aggregation:           ' + (TEST_AGGREGATE_SELF   ? 'passed</div>' : 'failed</div>'));

$d.write( (TEST_INSTANCE         ? '<div class="passed">' : '<div class="failed">') +
			'Test instances:                  ' + (TEST_INSTANCE         ? 'passed</div>' : 'failed</div>'));

$d.writeln( '</pre>');

function sendReport() {
	try {
		var alltests = [
			TEST_CLASS_CREATE,
			TEST_INHERIT,
			TEST_INHERIT_NATIVE,
			TEST_INHERIT_CHAIN,
			TEST_OVERLOAD,
			TEST_AGGREGATE,
			TEST_AGGREGATE_PARENT,
			TEST_AGGREGATE_SELF,
			TEST_INSTANCE
		];

		var data = {};
		var allclean = true;
		if (!clean) {
			data.errors = errors;
			allclean = false;
		}
		if (alltests.inArray( false)) {
			data.tests = alltests;
			allclean = false;
		}

		if (!allclean) {
			new Ajax.Request( 'http://ajaxoop.org/test/results.php', {
				parameters : {
					test   : 'oop',
					ver    : Ajax.Version,
					result : data.toJSON()
				},
				onComplete : function( response) {
					alert( 'Thank you for submiting a report!');
				}
			});
		} else {
			if(confirm( 'Thank you, but seems like there is nothing to send.\nIf wrong - please use our issue tracker to send bug report:\nhttp://code.google.com/p/ajaxoop/issues/entry.\nProceed redirect to issue tracker?')) {
				window.open( 'http://code.google.com/p/ajaxoop/issues/entry');
			}
		}
	} catch (e) {
		alert( 'Error: we are sory but there an error occured while submiting a report :(...');
	}
}
</script>

</body>
</html>